import {
    getmyprocesslist,
    getApplyType
} from '@/services/flowMine/myapplication';
import { dictionaryList } from '@/services/dictionary';

export default {
    namespace: 'myapply',
    state: {
        flowType: [],
        processStatusType: [],
        data: [],
        orderBy: '',
        pagination: {
            current: 1,
            total: 0,
            pageSize: 10
        }
    },
    effects: {
        *fetchFlowType({ payload }, { call, put }) {
            const result = yield call(getApplyType, payload);

            if (result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        flowType: result.data
                    }
                });
            }
        },
        *fetchProcessStatusType({ payload }, { call, put }) {
            const result = yield call(dictionaryList, payload);

            if (result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        processStatusType: result.data
                    }
                });
            }
        },
        *fetchList({ payload }, { call, put }) {
            const result = yield call(getmyprocesslist, payload);

            if (result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        data: result.data.rows,
                        pagination: {
                            current: result.data.pageNo,
                            pageSize: result.data.pageSize,
                            total: result.data.total
                        }
                    }
                });
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        }
    }
};
